image: {{ $.ModuleName }}/{{ $.ImageName }}
fromImage: common/distroless
import:
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-binaries-artifact
  add: /relocate
  to: /
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-binaries-artifact
  add: /
  to: /
  includePaths:
  - lib64/iptables
  - lib64/libm*
  before: setup
- image: common/iptables-wrapper
  add: /iptables-wrapper
  to: /sbin/iptables-wrapper
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-coredns-artifact
  add: /src/coredns
  to: /coredns
  before: setup
docker:
  ENTRYPOINT: ["/coredns"]
---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-coredns-artifact
from: {{ $.Images.BASE_GOLANG_20_ALPINE_DEV }}
mount:
- fromPath: ~/go-pkg-cache
  to: /go/pkg
shell:
  install:
  - export GO_VERSION=${GOLANG_VERSION}
  - export GOPROXY={{ $.GOPROXY }}
  - mkdir -p /src
  - git clone --depth 1 --branch v1.9.3 {{ $.SOURCE_REPO }}/coredns/coredns.git /src
  - cd /src
  - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags="-s -w" -o coredns
  - chmod -R 0700 /src/coredns
  - chown -R 64535:64535 /src/coredns
---
{{ $corednsBinaries := "/usr/bin/dig /bin/echo /usr/bin/curl /usr/bin/jq /bin/bash /bin/grep /sbin/ip /usr/bin/iptables* /sbin/iptables* /sbin/ip6tables* /sbin/xtables* /sbin/arptables*" }}
---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-binaries-artifact
from: {{ $.Images.BASE_ALT_DEV }}
git:
- add: /{{ $.ModulePath }}modules/350-{{ $.ModuleName }}/images/{{ $.ImageName }}
  to: /relocate
  stageDependencies:
    install:
    - '**/*'
  includePaths:
    - '*.sh'
shell:
  install:
    - /binary_replace.sh -i "{{ $corednsBinaries }}" -o /relocate
    - |
      for cmd in iptables iptables-save iptables-restore ip6tables ip6tables-save ip6tables-restore; do
        rm -f "/relocate/sbin/${cmd}"
        ln -s /sbin/iptables-wrapper "/relocate/sbin/${cmd}"
      done
